package net.midnighttd.engine.map;

import java.util.LinkedList;
import java.awt.*;

/**
 * Author: Adam Scarr
 * Date: 20/04/2009
 * Time: 3:16:36 PM
 */
public class MapManager extends LinkedList<Map> {
    public boolean isPassable(int x, int y) {

        for(Map map: this) {
            if(!map.inBounds(x,y)) return false;
            if(map.get(x,y) == null) continue;
            if(!map.get(x,y).isPassable()) return false;
        }

        return true;
    }

    public int getHeight() {
        int height = 0;
        for(Map m: this) {
            if (m.getHeight() > height) height = m.getHeight();
        }

        return height;
    }

    public int getWidth() {
        int width = 0;
        for(Map m: this) {
            if (m.getWidth() > width) width = m.getWidth();
        }

        return width;
    }

    public Point getWorldLocation(Point p) {
        Point q = new Point();
        if(size() == 0) return q;
        q.x = p.x / get(0).getTileset().getTilewidth();
        q.y = p.y / get(0).getTileset().getTileheight();

        return q;
    }

    public Dimension getTileSize() {
        if(size() == 0) return new Dimension(1,1);
        return new Dimension(get(0).getTileset().getTilewidth(), get(0).getTileset().getTileheight());
    }
}
